package No1_100.No31_40.CountandSay_38;

public class Solution {
    public String countAndSay(int n) {
        String[] a = new String[n];
        a[0] = "1";
        int i = 1;
        while(i < n){
            int count = 1;
            char digit = a[i-1].charAt(0);
            a[i] = "";
            for(int j = 1;j<a[i-1].length();j++){
                if (digit == a[i-1].charAt(j)) {
					count++;
				}else {
					a[i] += count +""+digit;
					digit = a[i-1].charAt(j);
					count = 1;
				}
            }
            a[i] += count +""+digit;
            i++;
        }
        return a[n-1];
    }
    public static void main(String[] args) {
		Solution s = new Solution();
		System.out.println(s.countAndSay(4));
	}
}
